// mock数据
//import '@/mock/mockServe.js';
import '@/mock/mockServe.js'

import './public-path'
import defaultSetting from './settings'
import Vue from 'vue'
import Cookies from 'js-cookie'
import Element from 'element-ui'
import '@/assets/styles/common.scss'
import '@/assets/styles/ht.css'
import HtComponents from '@/assets/js/ht.umd.js'
import EleForm from "vue-ele-form";
import EleDynamic from "vue-ele-form-dynamic";
import "./assets/styles/element-variables.scss";
import "@/assets/styles/index.scss"; // global css
import "@/assets/styles/ruoyi.scss"; // ruoyi css
import "@/assets/styles/HtTable.scss"; // 自定义 css
import "@/assets/styles/customer.scss"; // 自定义 css
import App from './App'
import store from './store'
import router from './router'
import permission from './directive/permission'

import './assets/icons' // icon
import './permission' // permission controlimport {
import {
  getDicts,
  getDictsList
} from "@/api/authority_app/dict/data";
import {
  changeAttrByPropGlobal,
  getUserInfoGlobal,
  printTable,
  createTable,
  getDateStr
} from "@/utils/form";
import currency from "currency.js";
import {
  returnFloat
} from "@/utils/common";
import {
  getConfigKey
} from "@/api/system/config";
import {
  parseTime,
  resetForm,
  addDateRange,
  selectDictLabel,
  selectDictLabels,
  download,
  handleTree,
} from "@/utils/ruoyi";
import "@/utils/validate";
import { getTokenForCookie } from "@/utils/auth";
import i18n from './language/index'

import Print from 'vue-printjs'

//封装的与外部容器交互的api方法
import { receiveParentMsg } from "@/utils/parent_connect/receiveParentApi"
import { baseUrlConfig, importReq, getReq, exportReq, postReq, delReq, listReq, listReqNoBody } from "@/api/authority_app/base";
import locale from "element-ui/src/mixins/locale";

// mock数据
//import '@/mock/mockServe.js';
//import '@/mock/mockServe.js'

//监听获取到的参数
receiveParentMsg();

// 全局方法挂载
//-----------------------------------------------------
Vue.prototype.currency = currency;
Vue.prototype.getDateStr = getDateStr;
Vue.prototype.returnFloat = returnFloat;
Vue.prototype.changeAttrByPropGlobal = changeAttrByPropGlobal;
Vue.prototype.getUserInfoGlobal = getUserInfoGlobal;
Vue.prototype.printTable = printTable;
Vue.prototype.createTable = createTable;
Vue.prototype.$confirmLoading = function (msg, title, settings) {
  this.$confirm(
    msg,
    title, {
      confirmButtonText: settings.confirmButtonText,
      cancelButtonText: settings.cancelButtonText,
      type: settings.type,
      beforeClose: (action, ctx, close) => {
        if (action != "confirm") {
          close();
          return;
        }
        ctx.confirmButtonLoading = true;
        settings.confirmFn()
          .then((res) => {
            close()
            settings.confirmFnThen(res);
          })
          .finally(() => {
            ctx.confirmButtonLoading = false;
          });
      },
    }
  ).catch(() => {});
};
// 全局方法挂载
Vue.prototype.getDicts = getDicts
Vue.prototype.getDictsList = getDictsList
Vue.prototype.getConfigKey = getConfigKey
Vue.prototype.parseTime = parseTime
Vue.prototype.resetForm = resetForm
Vue.prototype.addDateRange = addDateRange
Vue.prototype.selectDictLabel = selectDictLabel
Vue.prototype.selectDictLabels = selectDictLabels
Vue.prototype.download = download
Vue.prototype.handleTree = handleTree
Vue.prototype.$EventBus = new Vue();
Vue.prototype.cookie = Cookies;

Vue.prototype.$EventBus = new Vue();
Vue.prototype.cookie = Cookies;
Vue.prototype.lang = function (key, params = {}) {
  return this.$i18n.t(key, params)
}
Vue.prototype.t = function (key, params = {}) {
  return this.$i18n.t(key, params)
}

Vue.prototype.msgSuccess = function (msg) {
  this.$message({ showClose: true, message: msg, type: "success" });
}

Vue.prototype.msgError = function (msg) {
  this.$message({ showClose: true, message: msg, type: "error" });
}

Vue.prototype.msgWarning = function (msg) {
  this.$message({ showClose: true, message: msg, type: "warning" });
}

Vue.prototype.msgInfo = function (msg) {
  this.$message.info(msg);
}

Vue.use(permission)
// element-ui 选项参数
let initOption = {
  elementUI: {
    // set element-ui default size
    size: 'mini', //'medium'
    i18n: (key, value) => i18n.t(key, value)
  },
  htUI: {
    i18n: (key, value) => i18n.t(key, value)
  },
  requestUtil: {
    baseUrlConfig: baseUrlConfig,
    ctx: defaultSetting.ctx,
    getToken: getTokenForCookie,
    getReq,
    postReq,
    importReq,
    exportReq,
    delReq,
    listReq,
    listReqNoBody,
    getDictsList,
    ctxFileService: defaultSetting.ctxFileService
  }
}
// 装载 Element
Vue.use(Element, initOption.elementUI)
// 装载 华腾组件库
Vue.use(HtComponents, initOption)


Vue.use(Print)

Vue.use(EleForm, {
  upload: {
    action: "https://www.xxxx.com",
    responseFn(response) {
      // 因为是 mock 地址, 所以, 总是返回同一张图片的URL, 正常使用的时候不会
      return response.url;
    }
  },
  "upload-file": {
    responseFn(response, file) {
      return {
        name: file.name,
        url: URL.createObjectURL(file.raw),
        size: file.size
      };
    }
  },
  bmap: {
    ak: "9YLHZRPvUNLhi34Oh2ojqeGSpzCf1rVG"
  }
});
Vue.component("dynamic", EleDynamic);
Vue.config.productionTip = false

//mock 数据(根据环境变量配置来是否加载)
console.log('mock',process.env.VUE_APP_MOCK)
if(process.env.VUE_APP_MOCK === "true") {
  //require('./mock/index.js')
  require('./mock/index.js')
}
let instance = null;
function render(props = {}) {
  const { container } = props;
  instance = new Vue({
    //el: '#app',
    router,
    i18n,
    store,
    render: h => h(App)
  }).$mount(container ? container.querySelector('#app') : '#app')
}

render();


